<template>
  <div id="app">
    <h2>练习axios的CRUD操作</h2>
    <router-view></router-view>
  </div>
</template>

<script>
  import axios from "axios"
  export default {
    name: 'App',
    async mounted(){
      const axiosIns = axios.create({
        baseURL:"https://api.github.com"
      })
      axiosIns.interceptors.request.use(function (config) {
        config.headers.Authorization=
          "token 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"
        return config;
      });
      axiosIns.interceptors.response.use(function (response) {
        // 对响应数据做点什么
        return response.data;
      });
      //并发请求 同时发送两个以上的请求 而且只有等所有的请求都成功完成之后 才返回数据
      const p1 = axiosIns.get("/repos/betterDamu/bj_181130/issues")
      const p2 = axiosIns.get("/search/users",{params:{q:"damu"}})
      // const res = await Promise.all([p1, p2])
      // console.log(res);


      const res = await axios.all([p1,p2])
      console.log(res[0],res[1]);
      /*axios.all([p1,p2]).then(axios.spread((r1,r2)=>{
        console.log(r1, r2);
      }))*/
    }
  }
</script>

<style scoped>

</style>
